home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 2.iso / BARNET / COMPILER / SATHER / !Sather / Library / Base / sa / fltd < prev    next >
Text File  |  1996-07-18  |  21KB  |  724 lines

  1. ---------------------------> Sather 1.1 source file <--------------------------
  2. -- Copyright (C) International Computer Science Institute, 1994.  COPYRIGHT  --
  3. -- NOTICE: This code is provided "AS IS" WITHOUT ANY WARRANTY and is subject --
  4. -- to the terms of the SATHER LIBRARY GENERAL PUBLIC LICENSE contained in    --
  5. -- the file "Doc/License" of the Sather distribution.  The license is also   --
  6. -- available from ICSI, 1947 Center St., Suite 600, Berkeley CA 94704, USA.  --
  7. --------> Please email comments to "sather-bugs@icsi.berkeley.edu". <----------
  8. ----------------------------------------------------------------------------
  9. immutable class FLTD < $NUMBER{FLTD}, $HASH, $FMT is
  10.    -- IEEE 754-1984 "double" format 64-bit floating point.
  11.    include COMPARABLE;
  12.  
  13.    
  14.    plus(f:SAME):SAME is        -- The sum of self and `f'. Built-in.
  15.       builtin FLTD_PLUS;
  16.    end;
  17.  
  18.    minus(f:SAME):SAME is    
  19.       -- The difference between self and `f'. Built-in.     
  20.       builtin FLTD_MINUS;
  21.    end;   
  22.     
  23.    negate:SAME is
  24.       -- The negation of self. Same as zero minus self,
  25.       -- except for IEEE rounding modes and the sign bit.
  26.       builtin FLTD_NEGATE;
  27.    end;
  28.  
  29.    times(f:SAME):SAME is    
  30.       -- The signed product of self and `f'. Built-in.
  31.       builtin FLTD_TIMES;
  32.    end;   
  33.     
  34.    div(f:SAME):SAME is        -- The quotient of self and `f'. Built-in.
  35.       builtin FLTD_DIV;
  36.    end;   
  37.     
  38.    is_eq(b:SAME):BOOL is
  39.       -- True if self and `b' have the same value 
  40.       builtin FLTD_IS_EQ;
  41.    end;
  42.    
  43.    is_lt(f:SAME):BOOL is    
  44.       -- True if self is less than `f'. Built-in.
  45.       builtin FLTD_IS_LT;
  46.    end;   
  47.  
  48.    is_bet(l,u:SAME):BOOL is return self.is_between(l,u) end; -- Another name for `is_between'.
  49.     
  50.    is_between(l,u:SAME):BOOL is
  51.       -- True if self between l and u.
  52.       return (l<=self and self<=u) or (u<=self and self<=l) end;
  53.  
  54.    is_within(tolerance,val:SAME):BOOL is
  55.       -- True if self close to (within absolute tolerance of) val.
  56.       return (self-val).abs<=tolerance;
  57.    end;
  58.  
  59.    hash:INT is
  60.       -- A lousy hash function, can someone suggest better?
  61.       return truncate.int;
  62.    end;
  63.  
  64.    is_finite:BOOL is        -- returns true if zero, subnormal or normal.
  65.       builtin FLTD_FINITE;
  66.    end;
  67.  
  68.    is_inf:BOOL is        -- returns true if infinite
  69.       builtin FLTD_ISINF;
  70.    end;
  71.  
  72.    is_nan:BOOL is        
  73.       -- returns true if NaN.  See somment at "is_nil".
  74.       return ~(self=self);
  75.    end;
  76.  
  77.    is_normal:BOOL is        -- returns true if normal
  78.       builtin FLTD_ISNORMAL;
  79.    end;
  80.  
  81.    is_subnormal:BOOL is        -- returns true if subnormal
  82.       builtin FLTD_ISSUBNORMAL;
  83.    end;
  84.  
  85.    is_zero:BOOL is        -- returns true is zero
  86.         builtin FLTD_ISZERO;
  87.    end;
  88.  
  89.    signbit_set:BOOL is        -- returns true if sign bit of self is set
  90.         builtin FLTD_SIGNBIT;
  91.    end;
  92.  
  93.    unbiased_exponent:INT is
  94.       -- return unbiased exponent of self as an INT;
  95.       -- for zero this is INT::maxint.negate, for an
  96.       -- infinite it is INT::maxint.  If subnormal,
  97.       -- normalization occurs first.
  98.       builtin FLTD_ILOGB;
  99.    end;
  100.  
  101.    copysign(y:SAME):SAME is
  102.       -- return self with the sign bit set to the same as y's sign bit.
  103.       builtin FLTD_COPYSIGN;
  104.    end;
  105.  
  106.    nextup:FLTD is        -- return next representable number from self.
  107.       builtin FLTD_NEXTUP;
  108.    end;
  109.  
  110.    nextdown:FLTD is        
  111.       -- return previous representable number from self.
  112.       builtin FLTD_NEXTDOWN;
  113.    end;
  114.  
  115.    remainder(y:FLTD):FLTD is
  116.       --  x.remainder(y) and x.mod(y) return a remainder of x with respect
  117.       --  to y; that is, the result r is one of the numbers that differ from
  118.       --  x by an integral multiple of y.  Thus (x-r)/y  is an integral
  119.       --  value, even though it might exceed INT::maxint if it were
  120.       --  explicitly computed as an INT.  Both functions return one  of the
  121.       --  two such r smallest in magnitude.  remainder(x,y) is the operation
  122.       --  specified in ANSI/IEEE Std 754-1985; the result of x.mod(y) may
  123.       --  differ from remainder's result by +-y.  The magnitude of
  124.       --  remainder's result can not exceed half that of y; its sign might
  125.       --  not agree with either x or y.  The magnitude of mod's result is
  126.       --  less than that of y; its sign agrees with that of x.  Neither
  127.       --  function will raise an exception as long as both arguments are
  128.       --  normal or subnormal.  x.remainder(0), x.mod(0), oo.remainder(y),
  129.       --  and oo.mod(y) are invalid operations that produce a NaN.
  130.       builtin FLTD_REMAINDER;
  131.    end;
  132.  
  133.    mod(y:FLTD):FLTD is
  134.       -- See the comment at FLT::remainder
  135.       builtin FLTD_FMOD;
  136.    end;
  137.  
  138.    scale_by(n:INT):FLTD is
  139.       -- return x*2.pow(n) computed by exponent manipulation rather
  140.       -- than by actually performing an exponentiation or a multiplication.
  141.       -- 1 <= x.abs.scale_by(-x.unbiased_exponent) < 2 for every x
  142.       -- except 0, infinity, and NaN.
  143.       builtin FLTD_SCALBN;
  144.    end;
  145.  
  146.    bessel_j0:SAME is
  147.       -- Bessel functions of the first and second kinds.  y0, y1 and yn have
  148.       -- logarithmic singularities at the origin, so they treat zero and
  149.       -- negative arguments the way log does.
  150.       builtin FLTD_J0;
  151.    end;
  152.  
  153.    bessel_j1:SAME is
  154.       -- See comment at `bessel_j0'.
  155.       builtin FLTD_J1;
  156.    end;
  157.  
  158.    bessel_jn(n:INT):SAME is
  159.       -- See comment at `bessel_j0'.
  160.       builtin FLTD_JN;
  161.    end;
  162.  
  163.    bessel_y0:SAME is
  164.       -- See comment at `bessel_j0'.
  165.       builtin FLTD_Y0;
  166.    end;
  167.  
  168.    bessel_y1:SAME is
  169.       -- See comment at `bessel_j0'.
  170.       builtin FLTD_Y1;
  171.    end;
  172.  
  173.    bessel_yn(n:INT):SAME is
  174.       -- See comment at `bessel_j0'.
  175.       builtin FLTD_YN;
  176.    end;
  177.  
  178.    erf:SAME is
  179.       -- error function:
  180.       --
  181.       --   x.erf = (1/sqrt(pi))*integrate(0,x,exp(-t^2)dt)
  182.       builtin FLTD_ERF;
  183.    end;
  184.  
  185.    one_minus_erf:SAME is
  186.       -- 1.0-self.erf, but computed in a way to avoid cancellation for
  187.       -- large self.
  188.       builtin FLTD_ERFC;
  189.    end;
  190.  
  191.    exp:SAME is            -- The exponential e^self.
  192.       -- Exponential, logarithm, power functions functions handle
  193.       -- exceptional arguments in the spirit of IEEE 754-1985.  So:
  194.       --
  195.       --    0.log is -infinity with a division by zero exception
  196.       --
  197.       --    For x<0, including -infinity, x.log is a quiet NaN with an
  198.       --    invalid op exception
  199.       --
  200.       --    For x=+infinity or a quiet NaN, x.log is x without exception
  201.       --
  202.       --    For a signaling NaN, x.log is a quiet NaN with an invalid op exception
  203.       --
  204.       --    1.log is zero without exception
  205.       --
  206.       -- For any other positive x, x.log is a normalized number with an
  207.       -- inexact exception.
  208.  
  209.       builtin FLTD_EXP;
  210.    end;
  211.     
  212.    exp_minus_one:SAME is    -- e^self-1.0, accurate even for tiny self.
  213.       -- See comment at `exp'.
  214.       builtin FLTD_EXPM1;
  215.    end;
  216.  
  217.    exp2:SAME is            -- 2^self
  218.       -- See comment at `exp'.
  219.       builtin FLTD_EXP2;
  220.    end;
  221.  
  222.    exp10:SAME is        -- 10^self.  Built-in.
  223.       -- See comment at `exp'.
  224.       builtin FLTD_EXP10;
  225.    end;
  226.     
  227.    log:SAME is            -- The natural logarithm of self.
  228.       -- See comment at `exp'.
  229.       builtin FLTD_LOG;
  230.    end;
  231.  
  232.    plus_one_log:SAME is        -- (self+1).log, accurate even for tiny self.
  233.       -- See comment at `exp'.
  234.       builtin FLTD_LOG1P;
  235.    end;
  236.  
  237.    log2:SAME is            -- The logarithm base two of self.
  238.       -- See comment at `exp'.
  239.       return self.log*log2_e;
  240.    end;
  241.  
  242.    log10:SAME is        -- The logarithm base ten of self.
  243.       -- See comment at `exp'.
  244.       builtin FLTD_LOG10;
  245.    end;
  246.  
  247.    pow(arg:SAME):SAME is
  248.       -- self raised to the arg'th power.  x.pow(0.0)=1.0 for all x.
  249.       -- See comment at `exp'.
  250.       builtin FLTD_POW;
  251.    end;
  252.  
  253.    acosh:SAME is        -- The inverse hyperbolic cosine of self.
  254.       -- Hyperbolic functions handle exceptional arguments in the
  255.       -- spirit of IEEE 754-1985.  So:
  256.       -- sinh and cosh return +-infinity on overflow
  257.       -- acosh returns a NaN if its argument is less than 1.0
  258.       -- atanh returns a NaN if its argument has an absolute value >1.0
  259.       builtin FLTD_ACOSH;
  260.    end;
  261.     
  262.    sinh:SAME is            -- The hyperbolic sine of self.
  263.       -- See comment at `acosh'.
  264.       builtin FLTD_SINH;
  265.    end;
  266.     
  267.    cosh:SAME is            -- The hyperbolic cosine of self.
  268.       -- See comment at `acosh'.
  269.       builtin FLTD_COSH;
  270.    end;
  271.     
  272.    tanh:SAME is            -- The hyperbolic tangent of self.
  273.       -- See comment at `acosh'.
  274.       builtin FLTD_TANH;
  275.    end;
  276.  
  277.    asinh:SAME is        -- The inverse hyperbolic sine of self.
  278.       -- See comment at `acosh'.
  279.       builtin FLTD_ASINH;
  280.    end;
  281.     
  282.    atanh:SAME is        -- The inverse hyperbolic tangent of self.
  283.       -- See comment at `acosh'.
  284.       builtin FLTD_ATANH;
  285.    end;
  286.  
  287.    acos:SAME is            
  288.       -- The arc sine of self in the range [0.0, pi]
  289.       -- Trigonometric functions handle exceptional arguments
  290.       -- in the spirit of IEEE 754-1985.  So:
  291.       --
  292.       --    +-infinity.sin, +-infinity.cos, +-infinity.tan return NaN
  293.       --
  294.       --    x.asin and x.acos with x.abs>1 return NaN
  295.       --
  296.       -- sinpi etc. are similar except they compute
  297.       -- self.sinpi=(self*pi).sin avoiding range-reduction issues because
  298.       -- their definition permits range reduction that is fast and exact
  299.       -- for all self.  The corresponding inverse functions compute
  300.       -- asinpi(x).
  301.       builtin FLTD_ACOS;
  302.    end;
  303.     
  304.    hypot(arg:SAME):SAME is
  305.       -- sqrt(self*self+arg*arg), taking precautions against unwarranted
  306.       -- IEEE exceptions.  +-infinity.hypot(arg) is +infinity for any arg,
  307.       -- even a NaN, and is exceptional only for a signaling NaN.
  308.       builtin FLTD_HYPOT;
  309.    end;
  310.  
  311.    sin:SAME is 
  312.       -- +-infinity.sin, +-infinity.cos, +-infinity.tan return NaN
  313.       -- x.asin and x.acos with x.abs>1 return NaN
  314.       -- sinpi etc. are similar except they compute
  315.       -- self.sinpi=(self*pi).sin avoiding range-reduction issues because
  316.       -- their definition permits range reduction that is fast and exact
  317.       -- for all self.  The corresponding inverse functions compute asinpi(x).
  318.       builtin FLTD_SIN;
  319.    end;
  320.  
  321.    cos:SAME is
  322.       -- See comment for `acos'.
  323.       builtin FLTD_COS;
  324.    end;
  325.  
  326.    sincos(out sin: SAME,out cos: SAME) is
  327.       -- Simultaneous computation of self.sin and self.cos.  This is faster
  328.       -- than independently computing them.
  329.       -- See comment for `acos'.
  330.       builtin FLTD_SINCOS;
  331.    end;
  332.  
  333.    tan:SAME is
  334.       -- See comment for `acos'.
  335.       builtin FLTD_TAN;
  336.    end;
  337.  
  338.    asin:SAME is            
  339.       -- The arc sine of self in the range [-pi/2, pi/2]
  340.       -- See comment for `acos'.
  341.       builtin FLTD_ASIN;
  342.    end;
  343.     
  344.    atan:SAME is            
  345.       -- The arc tangent of self in the range [-pi/2, pi/2].
  346.       -- See comment for `acos'.
  347.       builtin FLTD_ATAN;
  348.    end;
  349.  
  350.    atan2(f:SAME):SAME is
  351.       -- The arc tangent of self divided by f in the range [-pi, pi].
  352.       -- It chooses the quadrant specified by (self, arg).
  353.       -- See comment for `acos'.
  354.       builtin FLTD_ATAN2;
  355.    end;
  356.  
  357.    sinpi:SAME is 
  358.       -- See comment for `acos'.
  359.       builtin FLTD_SINPI;
  360.    end;
  361.  
  362.    cospi:SAME is
  363.       -- See comment for `acos'.
  364.       builtin FLTD_COSPI;
  365.    end;
  366.  
  367.    sincospi(out s,out c:SAME) is
  368.       -- Simultaneous computation of self.sinpi and self.cospi.  This is faster
  369.       -- than independently computing them.
  370.       -- See comment for `acos'.
  371.       builtin FLTD_SINCOSPI;
  372.    end;
  373.  
  374.    tanpi:SAME is
  375.       -- See comment for `acos'.
  376.       builtin FLTD_TANPI;
  377.    end;
  378.  
  379.    asinpi:SAME is
  380.       -- (1/pi) times the arc sine of self.
  381.       -- Result in the range [-1/2, 1/2]
  382.       -- See comment for `acos'.
  383.       builtin FLTD_ASINPI;
  384.    end;
  385.     
  386.    acospi:SAME is 
  387.       -- (1/pi) times the arc cosine of self.
  388.       -- Result in the range [0, 1]
  389.       -- See comment for `acos'.
  390.       builtin FLTD_ACOSPI;
  391.    end;
  392.     
  393.    atanpi:SAME is 
  394.       -- (1/pi) times the arc tangent of self.
  395.       -- Result in the range [-1/2, 1/2]
  396.       -- See comment for `acos'.
  397.       builtin FLTD_ATANPI;
  398.    end;
  399.  
  400.    atan2pi(f:SAME):SAME is
  401.       -- (1/pi) times the arc tangent of self divided by f.
  402.       -- Result in the range [-1, 1].
  403.       -- It chooses the quadrant specified by (self, arg).
  404.       -- See comment for `acos'.
  405.       builtin FLTD_ATAN2PI;
  406.    end;
  407.  
  408.    abs:SAME is            
  409.       -- The absolute value of self.
  410.       builtin FLTD_FABS;
  411.    end;
  412.     
  413.    sign:SAME is
  414.       -- Returns -1.0d, 0.0d or 1.0d depending on sign of self.
  415.       if self<0.0d then return -1.0d;
  416.       elsif self>0.0d then return 1.0d;
  417.       else return self;
  418.       end;
  419.    end;
  420.  
  421.    signum:SAME is return sign end; -- Another name for `sign'.
  422.     
  423.    log_gamma:SAME is
  424.       -- log gamma function.  x.ln_gamma=x.gamma.abs.log
  425.       builtin FLTD_LGAMMA;
  426.    end;
  427.  
  428.    gamma:SAME is
  429.       -- gamma function.
  430.       if self>0.0d then return log_gamma.exp;
  431.       elsif integral then return 0.0d; -- ? Is this correct?
  432.       elsif abs.floor.int.is_even then return -log_gamma.exp;
  433.       else return log_gamma.exp;
  434.       end;
  435.    end;
  436.  
  437.    sqrt:SAME is            -- The square root of self.
  438.       builtin FLTD_SQRT;
  439.    end;
  440.     
  441.    square:SAME is        -- The square of self.
  442.       return self*self;
  443.    end;
  444.     
  445.    cube_root:SAME is        -- The cube root of self.
  446.       builtin FLTD_CBRT;
  447.    end;
  448.     
  449.    cube:SAME is            -- The cube of self.
  450.       return self*self*self;
  451.    end;
  452.  
  453.    max(arg:SAME):SAME is    -- The larger of self and arg.
  454.       -- Caution: may not behave as expected if one argument is a NaN.
  455.       if self<arg then return arg; else return self; end;
  456.    end;
  457.     
  458.    min(arg:SAME):SAME is    -- The smaller of self and arg.
  459.       -- Caution: may not behave as expected if one argument is a NaN.
  460.       if self<arg then return self; else return arg; end;
  461.    end;
  462.     
  463.    at_least(arg:SAME):SAME is return self.max(arg) end; -- Same as `self.max(arg)'
  464.    at_most(arg:SAME):SAME is return self.min(arg) end; -- Same as `self.min(arg)'
  465.  
  466.    str:STR is 
  467.       -- A string version of self.  
  468.       fdbuf:FSTR:=#(30);  -- fdbuf used to be shared, but this was
  469.               -- changed to make the class reentrant.
  470.               -- Same thing happens in FLT.  Other str
  471.               -- methods do the same thing.
  472.       -- if ((void(fdbuf)) or (fdbuf.size < 30)) then fdbuf := #FSTR(30) end;
  473.       fstr ::= str_in(fdbuf);
  474.       return(fstr.str); end;
  475.     
  476.    str(prec:INT):STR is 
  477.       -- A string version of self with "prec" digits of precision.
  478.       fdbuf:FSTR;
  479.       des_sz ::= prec+10;
  480.       if ((void(fdbuf)) or (fdbuf.size<des_sz)) then 
  481.      fdbuf:=#FSTR(des_sz) end;
  482.       fstr ::= str_in(fdbuf,prec);
  483.       return(fstr.str);  end;
  484.     
  485.    str_in(arg:FSTR):FSTR is 
  486.       -- Return an FSTR representation of self using the space in 
  487.       -- arg if possible
  488.       store_in: FSTR;
  489.       if (arg.size >= 30) then store_in := arg;
  490.       else store_in := #FSTR(30) end;
  491.       sz ::= store_into(store_in); 
  492.       store_in.loc := sz;
  493.       return(store_in); end;
  494.  
  495.    str_in(arg:FSTR, prec: INT): FSTR is
  496.       -- Return FSTR version of  self with precicsion of "prec" using the
  497.       -- space in arg if possible. 
  498.       store_in: FSTR;
  499.       des_sz ::= prec+10;
  500.       if (arg.size > des_sz) then store_in := arg
  501.       else store_in := #FSTR(des_sz) end;
  502.       sz ::= store_into_prec(prec,store_in);
  503.       store_in.loc := sz;
  504.       return(store_in);  end;
  505.     
  506.    private store_into(s:FSTR):INT is
  507.       -- Store the acsii representation into s.  Built-in.
  508.       builtin FLTD_STORE_INTO;
  509.    end;
  510.  
  511.    private store_into_prec(p:INT,s:FSTR):INT is
  512.       -- Store the acsii representation into s with precision p.  Built-in.
  513.       builtin FLTD_STORE_INTO_PREC;
  514.    end;
  515.  
  516.    fmt( f: STR ): STR
  517.       -- Convert into a nice ascii string.  See the separate document
  518.       -- for FMT for the details.
  519.    is
  520.       return BASE_FORMAT::fmt_flt( self, f )
  521.    end;
  522.    
  523.    create (s: STR): SAME is
  524.       builtin FLTD_ATOF;
  525.    end;
  526.     
  527.    create(f:INT):SAME is return f.fltd end;
  528.    create(f:INTI):SAME is return f.fltd end;
  529.    create(f:FLT):SAME is return f.fltd end;
  530.    create(f:FLTD):SAME is return f end;
  531.    --    create(f:FLTX):SAME is return f.fltd end;
  532.    --    create(f:FLTDX):SAME is return f.fltd end;
  533.    --    create(f:FLTI):SAME is return f.fltd end;
  534.     
  535.    integral:BOOL is return self.is_integral end; -- Same as `is_integral'
  536.     
  537.    is_integral:BOOL is
  538.       -- Return true if self is integral.
  539.       return self=truncate;
  540.    end;
  541.     
  542.    int:INT post result.fltd=self is
  543.       -- INT version of self.  It is an error if self is not integral.
  544.       -- Use truncate, floor, ceiling, or round to achieve this.
  545.       -- Built-in.
  546.       builtin FLTD_INT;
  547.    end;
  548.     
  549.    inti:INTI is return #INTI(self) end; -- Convert to INTI.
  550.     
  551.    flt:FLT is
  552.       -- A floating point version of self. It is an error if the
  553.       -- value cannot be held in a FLT. Built-in.
  554.       builtin FLTD_FLT; end;
  555.     
  556.    fltd:FLTD is return self end;  -- Convert to FLTD.  Identity operation.
  557.    
  558.    get_representation(out sign: BOOL,out exp: INT,out mlo: INT,out mhi: INT)
  559.       -- Gets the internal representation as sequence of INTs.
  560.    is
  561.       builtin FLTD_GET_REP;
  562.    end;
  563.  
  564.    truncate:SAME is        -- The nearest integer toward zero.  Built-in.
  565.       builtin FLTD_TRUNCATE;
  566.    end;
  567.     
  568.    floor:SAME is        -- The largest integer not greater than self.
  569.       builtin FLTD_FLOOR;
  570.    end;
  571.     
  572.    ceiling:SAME is        -- The smallest integer not less than self.
  573.       builtin FLTD_CEIL;
  574.    end;
  575.     
  576.    round:SAME is        -- The closest integer to self.  Built-in.
  577.       builtin FLTD_ROUND;
  578.    end;
  579.  
  580.    pi:SAME is
  581.       -- An approximation of the mathematical value "pi".  Built-in.
  582.       builtin FLTD_PI;
  583.    end;
  584.     
  585.    e:SAME is
  586.       -- An approximation of the base of the natural logarithms "e".  Built-in.
  587.       builtin FLTD_E;
  588.    end;
  589.  
  590.    sqrt_2:SAME is
  591.       -- Approximation of 2.sqrt.  Built-in.
  592.       builtin FLTD_SQRT_2;
  593.    end;
  594.  
  595.    log_2:SAME is
  596.       -- Approximation of 2.log.  Built-in.
  597.       builtin FLTD_LOG_2;
  598.    end;
  599.  
  600.    log2_e:SAME is
  601.       -- Approximation of e.log2.  Built-in.
  602.       builtin FLTD_LOG2_E;
  603.    end;
  604.  
  605.    log10_e:SAME is
  606.       -- Approximation of e.log10.  Built-in.
  607.       builtin FLTD_LOG10_E;
  608.    end;
  609.  
  610.    log_10:SAME is
  611.       -- Approximation of 10.log.  Built-in.
  612.       builtin FLTD_LOG_10;
  613.    end;
  614.  
  615.    half_pi:SAME is
  616.       -- Approximation of pi/2.  Built-in.
  617.       builtin FLTD_HALF_PI;
  618.    end;
  619.  
  620.    quarter_pi:SAME is
  621.       -- Approximation of pi/4.  Built-in.
  622.       builtin FLTD_QUARTER_PI;
  623.    end;
  624.  
  625.    inv_sqrt_2:SAME is
  626.       -- Approximation of 1/(2.sqrt).  Built-in.
  627.       builtin FLTD_INV_SQRT_2;
  628.    end;
  629.  
  630.    inv_pi:SAME is
  631.       -- Approximation of 1/pi.  Built-in.
  632.       builtin FLTD_INV_PI;
  633.    end;
  634.  
  635.    double_inv_pi:SAME is
  636.       -- Approximation of 2/pi.  Built-in.
  637.       builtin FLTD_DOUBLE_INV_PI;
  638.    end;
  639.  
  640.    double_sqrt_pi:SAME is
  641.       -- Approximation of 2*(pi.sqrt).  Built-in.
  642.       builtin FLTD_DOUBLE_SQRT_PI;
  643.    end;
  644.  
  645.    nil:SAME is
  646.       -- See $NIL for use of `nil'. nil for FLTD is a signalling NaN.
  647.       return signaling_NaN(0); 
  648.    end;
  649.  
  650.    is_nil:BOOL is
  651.       -- True is self is a NaN.
  652.       return ~(self=self);
  653.       -- Blame IEEE arithmetic for this.  I know how awful it looks.
  654.       -- It works because NaN is the only value which won't compare
  655.       -- with anything.
  656.    end;
  657.  
  658.    signaling_NaN(sig:INT):SAME is
  659.       -- IEEE signalling NaN.  `sig' is the significand (presently unused).
  660.       builtin FLTD_SIGNALING_NAN;
  661.    end;
  662.  
  663.    quiet_NaN(sig:INT):SAME is 
  664.       -- IEEE quiet NaN.  `sig' is the significand (presently unused).
  665.       builtin FLTD_QUIET_NAN;
  666.    end;
  667.  
  668.    infinity:SAME is        -- IEEE Infinity.
  669.       builtin FLTD_INFINITY;
  670.    end;
  671.  
  672.    const zero:SAME := 0.0d;              -- See $NUMBER.
  673.    const one: FLTD := 1.0d;
  674.    maxval:SAME is return infinity; end;  -- Maximal value; see $NUMBER.
  675.    minval:SAME is return -infinity; end; -- Minimal value; see $NUMBER.
  676.     
  677.    const epsilon:SAME:=2.2204460492503131e-16d;
  678.    -- The minimum x>0.0 such that 1.0+x/=x. 
  679.     
  680.    const digits:INT:=15;    -- The number of decimal digits of precision.
  681.  
  682.    const mantissa_bits:INT:=53;
  683.       -- The number of bits in the significand, including an implied bit.
  684.     
  685.    min_normal:SAME is        -- The smallest normal positive number.
  686.       builtin FLTD_MIN_NORMAL;
  687.    end;
  688.  
  689.    max_normal:SAME is        -- The largest normal positive number.
  690.       builtin FLTD_MAX_NORMAL;
  691.    end;
  692.  
  693.    min_subnormal:SAME is    -- The smallest subnormal positive number.
  694.       builtin FLTD_MIN_SUBNORMAL;
  695.    end;
  696.     
  697.    max_subnormal:SAME is    -- The largest subnormal positive number.
  698.       builtin FLTD_MAX_SUBNORMAL;
  699.    end;
  700.     
  701.    const min_exp:INT:=-1021;
  702.       -- The minimum negative integer x such that b^(x-1) is in the range
  703.       -- of normalized floating point numbers.
  704.    
  705.    const min_exp10:INT:=-307;
  706.       -- The minimum x such that 10^x is in the range of normalized
  707.       -- floating point numbers.
  708.     
  709.    const max_exp:INT:=1024;    -- The maximum allowable exponent.
  710.     
  711.    const max_exp10:INT:=308;    
  712.       -- The maximum x such that 10^x is within range.
  713.  
  714.    sum!(i:SAME):SAME is
  715.       -- Yields the sum of all previous values of `i'.
  716.       r::=0.0d; loop r:=r+i; yield r end end;
  717.     
  718.    product!(i:SAME):SAME is
  719.       -- Yields the product of all previous values of `i'.
  720.       r::=1.0d; loop r:=r*i; yield r end end;
  721.  
  722. end; -- class FLTD
  723. ----------------------------------------------------------------------------
  724.